use serde::{Deserialize, Serialize};
use wither::bson::{Bson, Document};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageModel {
    /// 社团页面标题
    pub title: String,
    /// 社团页面json结构(用于渲染页面)
    pub content: Option<Document>,
    /// 社团页面文本结构(html or 页面内的关键文字)
    pub content_text: Option<String>,
}
impl From<PageModel> for Document {
    fn from(c: PageModel) -> Self {
        let mut res_doc = option_doc!(
            "content":c.content,
            "content_text":c.content_text
        );
        res_doc.insert("title", c.title);
        res_doc
    }
}
impl From<PageModel> for Bson {
    fn from(c: PageModel) -> Self {
        Bson::Document(c.into())
    }
}
